class Admin::ScratchCardAwardsController < AdminController
  def index
    @scratch_card_awards = ScratchCardAward.all.order("created_at DESC").page(params[:page]).per(params[:per])
  end

  def new
    @scratch_card_award = ScratchCardAward.new
  end

  def create
    @scratch_card_award = ScratchCardAward.new scratch_card_award_params
    if @scratch_card_award.save
      redirect_to admin_scratch_card_awards_path, notice: "保存成功！"
    else
      redirect_to admin_scratch_card_awards_path, notice: "保存失败！"
    end
  end

  def edit
    @scratch_card_award = ScratchCardAward.find params[:id]
  end

  def update
    @scratch_card_award = ScratchCardAward.find params[:id]
    if @scratch_card_award.update scratch_card_award_params
      redirect_to admin_scratch_card_awards_path, notice: "更新成功！"
    else
      redirect_to admin_scratch_card_awards_path, notice: "更新失败！"
    end
  end
  
  def destroy
    @scratch_card_award = ScratchCardAward.find params[:id]
    if @scratch_card_award.destroy
      redirect_to admin_scratch_card_awards_path, notice: "删除成功."
    else
      redirect_to admin_scratch_card_awards_path, notice: "删除失败."
    end
  end

  private

  def scratch_card_award_params
    params.require(:scratch_card_award).permit(:name, :published, :chance)
  end
end
